﻿/// <reference path="../GeneratedArtifacts/viewModel.js" />

myapp.At13TraingroupSessionAddEdit.Delete_execute = function (screen) {
    screen.tbTrainsession.deleteEntity();
    return myapp.commitChanges().then(null, function fail(e) {
        myapp.cancelChanges();
        throw e;
    });
};

myapp.At13TraingroupSessionAddEdit.created = function (screen) {
    screen.tbTrainsession.addChangeListener('GroupStart', function () {
        // Date
        var startDate = screen.tbTrainsession.GroupStart.getDate();
        var endDate = screen.tbTrainsession.GroupEnd.getDate();
        if(startDate != endDate)
            screen.tbTrainsession.GroupEnd.setDate(screen.tbTrainsession.GroupStart.getDate());

        // Month
        var startMonth = screen.tbTrainsession.GroupStart.getMonth();
        var endMonth = screen.tbTrainsession.GroupEnd.getMonth();
        if (startMonth != endMonth)
            screen.tbTrainsession.GroupEnd.setMonth(screen.tbTrainsession.GroupStart.getMonth());

        // Year
        var startYear = screen.tbTrainsession.GroupStart.getYear();
        var endYear = screen.tbTrainsession.GroupEnd.getYear();
        if (startYear != endYear)
            screen.tbTrainsession.GroupEnd.setYear(screen.tbTrainsession.GroupStart.getYear());
    });

    screen.tbTrainsession.addChangeListener('GroupEnd', function () {
        // Date
        var startDate = screen.tbTrainsession.GroupStart.getDate();
        var endDate = screen.tbTrainsession.GroupEnd.getDate();
        if (startDate != endDate)
            screen.tbTrainsession.GroupStart.setDate(screen.tbTrainsession.GroupEnd.getDate());

        // Month
        var startMonth = screen.tbTrainsession.GroupStart.getMonth();
        var endMonth = screen.tbTrainsession.GroupEnd.getMonth();
        if (startMonth != endMonth)
            screen.tbTrainsession.GroupStart.setMonth(screen.tbTrainsession.GroupEnd.getMonth());

        // Year
        var startYear = screen.tbTrainsession.GroupStart.getYear();
        var endYear = screen.tbTrainsession.GroupEnd.getYear();
        if (startYear != endYear)
            screen.tbTrainsession.GroupStart.setYear(screen.tbTrainsession.GroupEnd.getYear());
    });
};